#tag Window
Begin Window MainWin
   BackColor       =   0
   Backdrop        =   ""
   CloseButton     =   True
   Composite       =   False
   Frame           =   0
   FullScreen      =   False
   HasBackColor    =   False
   Height          =   1.5e+2
   ImplicitInstance=   True
   LiveResize      =   False
   MacProcID       =   0
   MaxHeight       =   32000
   MaximizeButton  =   False
   MaxWidth        =   32000
   MenuBar         =   978669567
   MenuBarVisible  =   True
   MinHeight       =   64
   MinimizeButton  =   False
   MinWidth        =   64
   Placement       =   0
   Resizeable      =   False
   Title           =   "Library Player"
   Visible         =   True
   Width           =   3.0e+2
   Begin BevelButton revButton
      AcceptFocus     =   False
      AutoDeactivate  =   True
      BackColor       =   0
      Bevel           =   0
      Bold            =   False
      ButtonType      =   1
      Caption         =   ""
      CaptionAlign    =   3
      CaptionDelta    =   0
      CaptionPlacement=   1
      Enabled         =   True
      HasBackColor    =   False
      HasMenu         =   0
      Height          =   54
      HelpTag         =   ""
      Icon            =   ""
      IconAlign       =   0
      IconDX          =   0
      IconDY          =   0
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   False
      Left            =   0
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      MenuValue       =   0
      Scope           =   0
      TabIndex        =   0
      TabPanelIndex   =   0
      TabStop         =   True
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   ""
      TextUnit        =   0
      Top             =   95
      Underline       =   False
      Value           =   False
      Visible         =   True
      Width           =   60
   End
   Begin BevelButton stopButton
      AcceptFocus     =   False
      AutoDeactivate  =   True
      BackColor       =   0
      Bevel           =   0
      Bold            =   False
      ButtonType      =   0
      Caption         =   ""
      CaptionAlign    =   3
      CaptionDelta    =   0
      CaptionPlacement=   1
      Enabled         =   True
      HasBackColor    =   False
      HasMenu         =   0
      Height          =   54
      HelpTag         =   ""
      Icon            =   ""
      IconAlign       =   0
      IconDX          =   0
      IconDY          =   0
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   False
      Left            =   120
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      MenuValue       =   0
      Scope           =   0
      TabIndex        =   2
      TabPanelIndex   =   0
      TabStop         =   True
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   ""
      TextUnit        =   0
      Top             =   95
      Underline       =   False
      Value           =   False
      Visible         =   True
      Width           =   60
   End
   Begin BevelButton playButton
      AcceptFocus     =   False
      AutoDeactivate  =   True
      BackColor       =   0
      Bevel           =   0
      Bold            =   False
      ButtonType      =   0
      Caption         =   ""
      CaptionAlign    =   3
      CaptionDelta    =   0
      CaptionPlacement=   1
      Enabled         =   True
      HasBackColor    =   False
      HasMenu         =   0
      Height          =   54
      HelpTag         =   ""
      Icon            =   ""
      IconAlign       =   0
      IconDX          =   0
      IconDY          =   0
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   False
      Left            =   60
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      MenuValue       =   0
      Scope           =   0
      TabIndex        =   3
      TabPanelIndex   =   0
      TabStop         =   True
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   ""
      TextUnit        =   0
      Top             =   95
      Underline       =   False
      Value           =   False
      Visible         =   True
      Width           =   60
   End
   Begin BevelButton fwdButton
      AcceptFocus     =   False
      AutoDeactivate  =   True
      BackColor       =   0
      Bevel           =   0
      Bold            =   False
      ButtonType      =   1
      Caption         =   ""
      CaptionAlign    =   3
      CaptionDelta    =   0
      CaptionPlacement=   1
      Enabled         =   True
      HasBackColor    =   False
      HasMenu         =   0
      Height          =   54
      HelpTag         =   ""
      Icon            =   ""
      IconAlign       =   0
      IconDX          =   0
      IconDY          =   0
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   False
      Left            =   180
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      MenuValue       =   0
      Scope           =   0
      TabIndex        =   4
      TabPanelIndex   =   0
      TabStop         =   True
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   ""
      TextUnit        =   0
      Top             =   95
      Underline       =   False
      Value           =   False
      Visible         =   True
      Width           =   60
   End
   Begin StaticText row1
      AutoDeactivate  =   True
      Bold            =   ""
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   20
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   8
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Multiline       =   ""
      Scope           =   0
      TabIndex        =   6
      TabPanelIndex   =   0
      Text            =   ""
      TextAlign       =   0
      TextColor       =   0
      TextFont        =   "Verdana"
      TextSize        =   12
      TextUnit        =   0
      Top             =   0
      Underline       =   ""
      Visible         =   True
      Width           =   289
   End
   Begin StaticText row2
      AutoDeactivate  =   True
      Bold            =   True
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   20
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   ""
      Left            =   8
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Multiline       =   ""
      Scope           =   0
      TabIndex        =   7
      TabPanelIndex   =   0
      Text            =   ""
      TextAlign       =   0
      TextColor       =   0
      TextFont        =   "Verdana"
      TextSize        =   14
      TextUnit        =   0
      Top             =   24
      Underline       =   ""
      Visible         =   True
      Width           =   289
   End
   Begin PopupMenu PopupMenu1
      AutoDeactivate  =   True
      Bold            =   ""
      DataField       =   ""
      DataSource      =   ""
      Enabled         =   True
      Height          =   20
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      InitialValue    =   ""
      Italic          =   ""
      Left            =   0
      ListIndex       =   0
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Scope           =   0
      TabIndex        =   10
      TabPanelIndex   =   0
      TabStop         =   True
      TextFont        =   "System"
      TextSize        =   0
      TextUnit        =   0
      Top             =   70
      Underline       =   ""
      Visible         =   True
      Width           =   274
   End
   Begin BevelButton AddMarkButton
      AcceptFocus     =   False
      AutoDeactivate  =   True
      BackColor       =   0
      Bevel           =   0
      Bold            =   False
      ButtonType      =   0
      Caption         =   "+"
      CaptionAlign    =   3
      CaptionDelta    =   0
      CaptionPlacement=   1
      Enabled         =   True
      HasBackColor    =   False
      HasMenu         =   0
      Height          =   23
      HelpTag         =   ""
      Icon            =   ""
      IconAlign       =   0
      IconDX          =   0
      IconDY          =   0
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   False
      Left            =   275
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      MenuValue       =   0
      Scope           =   0
      TabIndex        =   11
      TabPanelIndex   =   0
      TabStop         =   True
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   ""
      TextUnit        =   0
      Top             =   69
      Underline       =   False
      Value           =   False
      Visible         =   True
      Width           =   22
   End
   Begin BevelButton exportButton
      AcceptFocus     =   False
      AutoDeactivate  =   True
      BackColor       =   0
      Bevel           =   0
      Bold            =   False
      ButtonType      =   0
      Caption         =   ""
      CaptionAlign    =   3
      CaptionDelta    =   0
      CaptionPlacement=   1
      Enabled         =   True
      HasBackColor    =   False
      HasMenu         =   0
      Height          =   54
      HelpTag         =   ""
      Icon            =   ""
      IconAlign       =   0
      IconDX          =   0
      IconDY          =   0
      Index           =   -2147483648
      InitialParent   =   ""
      Italic          =   False
      Left            =   240
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      MenuValue       =   0
      Scope           =   0
      TabIndex        =   13
      TabPanelIndex   =   0
      TabStop         =   True
      TextColor       =   0
      TextFont        =   "System"
      TextSize        =   ""
      TextUnit        =   0
      Top             =   95
      Underline       =   False
      Value           =   False
      Visible         =   True
      Width           =   60
   End
   Begin MoviePlayer player
      AutoDeactivate  =   True
      AutoPlay        =   ""
      AutoResize      =   False
      Border          =   False
      Controller      =   0
      HasStep         =   False
      Height          =   19
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Left            =   346
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Looping         =   ""
      Movie           =   ""
      Palindrome      =   ""
      PlayerType      =   2
      Scope           =   0
      Speaker         =   True
      TabIndex        =   14
      TabPanelIndex   =   0
      TabStop         =   True
      Top             =   95
      Visible         =   False
      Width           =   17
   End
   Begin Timer Timer1
      Height          =   32
      Index           =   -2147483648
      Left            =   337
      LockedInPosition=   False
      Mode            =   2
      Period          =   250
      Scope           =   0
      TabPanelIndex   =   0
      Top             =   24
      Width           =   32
   End
   Begin Slider Slider1
      AutoDeactivate  =   True
      Enabled         =   True
      Height          =   16
      HelpTag         =   ""
      Index           =   -2147483648
      InitialParent   =   ""
      Left            =   0
      LineStep        =   1
      LiveScroll      =   ""
      LockBottom      =   ""
      LockedInPosition=   False
      LockLeft        =   True
      LockRight       =   ""
      LockTop         =   True
      Maximum         =   100
      Minimum         =   0
      PageStep        =   20
      Scope           =   0
      TabIndex        =   15
      TabPanelIndex   =   0
      TabStop         =   True
      TickStyle       =   0
      Top             =   50
      Value           =   0
      Visible         =   True
      Width           =   300
   End
   Begin UpdaterSocket updSocket
      Height          =   32
      Index           =   -2147483648
      Left            =   337
      LockedInPosition=   False
      Path            =   ""
      Scope           =   0
      TabPanelIndex   =   0
      Top             =   -20
      Width           =   32
   End
   Begin Timer fwdTimer
      Height          =   32
      Index           =   -2147483648
      Left            =   337
      LockedInPosition=   False
      Mode            =   0
      Period          =   100
      Scope           =   0
      TabPanelIndex   =   0
      Top             =   139
      Width           =   32
   End
   Begin Timer revTimer
      Height          =   32
      Index           =   -2147483648
      Left            =   337
      LockedInPosition=   False
      Mode            =   0
      Period          =   100
      Scope           =   0
      TabPanelIndex   =   0
      Top             =   183
      Width           =   32
   End
End
#tag EndWindow

#tag WindowCode
	#tag Event
		Sub Close()
		  Searchwin.close
		  Rmmetawin.close
		  SetupWin.close
		  SearchWin.close
		  Aboutwin.close
		  AlbumImportWin.close
		  PlayMarksWin.close
		  ProgressWin.close
		  
		  if mydb<>nil then
		    mydb.Close
		  end
		  
		  app.mprefs.putinteger("MainWinTop",me.top)
		  app.mprefs.putinteger("MainWinLeft",me.left)
		  
		  do
		  loop until app.mPrefs.write()
		  
		  do
		  loop until app.lang.write()
		  
		  
		  
		End Sub
	#tag EndEvent

	#tag Event
		Sub Open()
		  me.title="Library Player "+str(app.MajorVersion)+"."+str(app.minorversion)
		  
		  if app.mprefs.getinteger("MainWinTop")>0 then
		    me.top=app.mPrefs.getinteger("MainWinTop")
		  else
		    me.top=100
		  end
		  
		  if app.mprefs.getinteger("MainWinLeft")>0 then
		    me.left=app.mPrefs.getinteger("MainWinLeft")
		  else
		    me.left=screen(0).width/2-me.width/2
		  end
		  
		  ExportButton.enabled=app.IsAdmin
		  
		  app.lang.LoadCaptions(self)
		  
		  
		End Sub
	#tag EndEvent


	#tag Method, Flags = &h0
		Sub ButtonRedraw()
		  dim state as boolean
		  
		  if player<>nil then
		    if player.duration>0 then
		      state=true
		    else
		      state=false
		    end
		  else
		    state=false
		  end
		  
		  //play
		  
		  dim butpic as controlButtonPict
		  butpic=new controlButtonPict(playbutton.Width-3, playbutton.Height-3,32)
		  butpic.create("PLAY",12,state)
		  playButton.Icon=butpic
		  
		  //fwd
		  
		  butpic=new controlButtonPict(fwdButton.Width-3, fwdButton.Height-3,32)
		  butpic.create(">>",12,fwdButton.value)
		  fwdButton.Icon=butpic
		  
		  //rev
		  
		  butpic=new controlButtonPict(revButton.Width-3, revButton.Height-3,32)
		  butpic.create("<<",12,revButton.value)
		  revButton.Icon=butpic
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub UpdateView()
		  if TheSong<>nil then
		    
		    ROW1.TEXT=ReplaceAll(TheSong.PERFORMER,"&","&&")
		    ROW2.TEXT=ReplaceAll(TheSong.TRACKNAME,"&","&&")
		    
		    if len(TheSong.HiResPath)>0 then
		      
		      dim f as folderitem
		      dim path as string
		      
		      if REALBasic.right(app.mprefs.getstring("musicurl"),1)="/" then
		        path=REALBasic.left(app.mprefs.getstring("musicurl"),len(app.mprefs.getstring("musicurl"))-1)
		      else
		        path=app.mprefs.getstring("musicurl")
		      end
		      
		      path=path+TheSong.HiResPath
		      
		      PlayableFile=GetFolderItem(TheSong.HiResPath)
		      
		      'if PlayableFile=nil then
		      'MsgBox "ERROR: Cannot play file "+TheSong.HiresPath
		      'end
		      
		      player.movie=OpenURLMovie(TheSong.HiResPath)
		      player.speaker=true
		      player.HasStep=true
		      player.play //hack needed since duration property is valid only while playing
		      DurationInSec=player.duration
		      player.stop
		      
		      slider1.maximum=DurationInSec
		      
		    end
		    
		    if len(TheSong.PLAYMARKSDATA)>0 then
		      
		      popupmenu1.DeleteAllRows
		      
		      for i as integer=1 to CountFields(TheSong.PLAYMARKSDATA,"|")
		        
		        PopupMenu1.addrow NthField(NthField(TheSong.PLAYMARKSDATA,"|",i),";",2)
		        Popupmenu1.RowTag(popupmenu1.listcount-1)=TimeToSecs(NthField(NthField(TheSong.PLAYMARKSDATA,"|",i),";",1))
		        
		      next
		    end
		  end
		End Sub
	#tag EndMethod


	#tag Property, Flags = &h0
		DurationInSec As Integer
	#tag EndProperty

	#tag Property, Flags = &h0
		PlayableFile As Folderitem
	#tag EndProperty

	#tag Property, Flags = &h0
		SliderMouseDown As Boolean
	#tag EndProperty

	#tag Property, Flags = &h0
		startX As Integer
	#tag EndProperty

	#tag Property, Flags = &h0
		TheSong As MusicDataObject
	#tag EndProperty

	#tag Property, Flags = &h0
		TransferStatus As integer
	#tag EndProperty


#tag EndWindowCode

#tag Events revButton
	#tag Event
		Sub Open()
		  dim butpic as controlButtonPict
		  butpic=new controlButtonPict(me.Width-3, me.Height-3,32)
		  butpic.create("<<",12,me.Value)
		  me.Icon=butpic
		End Sub
	#tag EndEvent
	#tag Event
		Sub Action()
		  
		  
		  if player<>nil then
		    if me.value then
		      revTimer.mode=2
		    else
		      revTimer.mode=0
		    end
		  end
		  
		  buttonredraw
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events stopButton
	#tag Event
		Sub Open()
		  dim butpic as controlButtonPict
		  butpic=new controlButtonPict(me.Width-3, me.Height-3,32)
		  butpic.create("STOP",12,me.Value)
		  me.Icon=butpic
		End Sub
	#tag EndEvent
	#tag Event
		Sub Action()
		  if player<>nil then
		    
		    revTimer.mode=0
		    fwdTimer.mode=0
		    revButton.value=false
		    fwdButton.value=false
		    playButton.Value=false
		    player.stop
		    
		  else
		    MsgBox "player is nil"
		  end
		  
		  Buttonredraw
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events playButton
	#tag Event
		Sub Action()
		  if fwdButton.Value then fwdButton.value=false
		  if revButton.value then revButton.value=false
		  
		  if player<>nil then
		    
		    player.play
		    
		  end
		  
		  buttonredraw
		  
		End Sub
	#tag EndEvent
	#tag Event
		Sub Open()
		  dim butpic as controlButtonPict
		  butpic=new controlButtonPict(me.Width-3, me.Height-3,32)
		  butpic.create("PLAY",12,me.Value)
		  me.Icon=butpic
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events fwdButton
	#tag Event
		Sub Open()
		  dim butpic as controlButtonPict
		  butpic=new controlButtonPict(me.Width-3, me.Height-3,32)
		  butpic.create(">>",12,me.Value)
		  me.Icon=butpic
		End Sub
	#tag EndEvent
	#tag Event
		Sub Action()
		  
		  if player<>nil then
		    if me.value then
		      fwdTimer.mode=2
		    else
		      fwdTimer.mode=0
		    end
		  end
		  
		  ButtonRedraw
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events PopupMenu1
	#tag Event
		Sub Change()
		  if me.listindex>-1 then
		    if me.rowtag(me.listindex)<>nil then
		      if player<>nil then
		        player.position=me.rowtag(me.listindex)
		      end
		    end
		  end
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events AddMarkButton
	#tag Event
		Sub Action()
		  if TheSong<>nil then
		    if len(TheSong.PLAYMARKSDATA)>0 then
		      TheSong.PLAYMARKSDATA=TheSong.PLAYMARKSDATA+"|"+SecsToTime(player.position)+";"
		    else
		      TheSong.PLAYMARKSDATA=SecsToTime(player.position)+";"
		    end
		    
		    PlayMarksWin.Show
		    PlayMarksWin.Update
		    
		  end
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events exportButton
	#tag Event
		Sub Action()
		  'ftp_session=New FTPSessionClass
		  '
		  'ftpfinished=false
		  '
		  'ftp_session.SetLoginInfo("localhost","radioman","Rad10Man")
		  '
		  'ftp_session.logon
		  '
		  'do
		  'loop until Ftpfinished
		  '
		  'FtpFinished=false
		  '
		  'ftp_session.SetLocalDirectoryPathName(SpecialFolder.Temporary.absolutepath)
		  '
		  'ftp_session.AddFileName("/HIRES/00/13.S44")
		  '
		  'ftp_session.SetTimeoutSeconds(10)
		  '
		  'ftp_session.PassiveMode=true
		  '
		  'ftp_session.GetSingleFile()
		  '
		  'do
		  'loop until FtpFinished
		  '
		  'ftp_session.Logoff
		  '
		  'PlayableFile=SpecialFolder.Temporary.Child("13.S44")
		  
		  
		End Sub
	#tag EndEvent
	#tag Event
		Sub Open()
		  dim butpic as controlButtonPict
		  butpic=new controlButtonPict(me.Width-3, me.Height-3,32)
		  butpic.create("EXPORT",12,me.Value)
		  me.Icon=butpic
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events Timer1
	#tag Event
		Sub Action()
		  
		  if player<>nil then
		    
		    dim pos as integer=player.position
		    
		    if TransferStatus>0 then
		      self.title="Transferring "+str(TransferStatus)+"..."
		    else
		      self.title=SecsToTime(pos)
		    end
		    
		    if player.position<slider1.maximum then
		      Slider1.value=pos
		    end
		    
		  end
		  
		  
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events Slider1
	#tag Event
		Function MouseDown(X As Integer, Y As Integer) As Boolean
		  startX=X
		  
		  return true
		End Function
	#tag EndEvent
	#tag Event
		Sub MouseUp(X As Integer, Y As Integer)
		  if player<>nil then
		    
		    player.position=player.position+(x-startX)
		    
		  end
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events updSocket
	#tag Event
		Sub QuitApplication()
		  MsgBox "Player will now quit in order to be updated."
		  
		  Quit
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events fwdTimer
	#tag Event
		Sub Action()
		  if player<>nil then
		    if player.position<player.Duration then
		      player.position=player.position+1
		    else
		      me.Mode=0
		      fwdButton.value=false
		    end
		  end
		End Sub
	#tag EndEvent
#tag EndEvents
#tag Events revTimer
	#tag Event
		Sub Action()
		  if player<>nil then
		    if player.position>0 then
		      player.position=player.position-1
		    else
		      me.mode=0
		      revButton.value=false
		    end
		  end
		End Sub
	#tag EndEvent
#tag EndEvents
